package com.bite.com.book;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @PostMapping(value = "/login")
    public boolean login(String name, String password, HttpSession session) {
        // 判断是否为空
        if (!StringUtils.hasLength(name)
            || !StringUtils.hasLength(password)) return false;
        // 验证（写死）
        // 正确登录后设置session
        if ("admin".equals(name) && "admin".equals(password)) {
            session.setAttribute("userName",name);
            return true;
        }
        return false;
    }
}
